package com.itheima.utils;

import com.itheima.dto.SlideBlockValidateCodeDTO;
import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultRequest;
import com.tencentcloudapi.captcha.v20190722.models.DescribeCaptchaResultResponse;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;

public class SlideBlockValidateCodeUtils {

    private static final String ENDPOINT = "captcha.tencentcloudapi.com";
    private static final String SECRETID = "AKIDaNsBMGoNZOyPyRwsP77yhJK8pKdj5W6g";
    private static final String SECRETKEY = "g7KJ4INI8MPDZgaSPqBZJbmrnWFl04c9";
    private static final String APPSECRETKEY = "0-SL651fDPGC1DWesyAVQKQ**";
    private static final String USERIP = "http://healthcz118.natapp1.cc";
    private static final Long CAPTCHATYPE = 9L;


    public static DescribeCaptchaResultResponse validate(SlideBlockValidateCodeDTO sbvc){
        DescribeCaptchaResultResponse resp = null;
        try{
            Credential cred = new Credential(SECRETID, SECRETKEY);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(ENDPOINT);
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            CaptchaClient client = new CaptchaClient(cred, "", clientProfile);
            DescribeCaptchaResultRequest req = new DescribeCaptchaResultRequest();
            req.setCaptchaType(CAPTCHATYPE);
            req.setTicket(sbvc.getTicket());
            req.setUserIp(USERIP);
            req.setRandstr(sbvc.getRandstr());
            req.setCaptchaAppId(Long.parseLong(sbvc.getAppid()));
            req.setAppSecretKey(APPSECRETKEY);
             resp = client.DescribeCaptchaResult(req);
            System.out.println(DescribeCaptchaResultResponse.toJsonString(resp));

        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
        return resp;
    }
}
